//
//  FirstViewController.m
//  XDCommonApp
//
//  Created by XD-XY on 2/12/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "FirstViewController.h"
#import "XDHeader.h"
#import "XDTools.h"
#import "UIButton+Category.h"
#import "HotPointProductionCell.h"
#import "HotPointNarrowCell.h"
#import "ActivityCell.h"
#import "UIImageView+WebCache.h"
#import "ActivityItem.h"
#import "StarArtistsItem.h"
#import "StarWorkItem.h"
#import "StarGalleryItem.h"

#import "DetailforActFirstVC.h"
#import "DetailforActSecondVC.h"
#import "DetailforActThirdVC.h"
#import "DetailforArtistVC.h"
#import "MostDetailViewController.h"

#import "DSAppController.h"

#define btn_tag 10000
#define cell_btn_tag 1
#define cell_btn_tag1 10
#define cell_btn_tag2 20

#define acitivtyHeaderHeight 43/2.0f  //活动列表每个section的头视图高度
#define hotHeaderViewHeight 177/2.0f  //数据热点头部图片高度
#define hotPointHeaderHeight 52/2.0f  //数据热点列表每个section的头视图高度
@interface FirstViewController ()

@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    rightBtn.frame = CGRectMake(130, 5, 60, 34);
    [rightBtn setTitle:@"图像识别" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(knowPic) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationBarView addSubview:rightBtn];
    
	// Do any additional setup after loading the view.
    bannerIndex = 0;
    self.leftBtn.hidden =YES;
    //检查版本更新
//   [[XDTools sharedXDTools] checkVersion:self isShowAlert:YES];
    
    [[NSUserDefaults standardUserDefaults] setObject:@"yes" forKey:@"SecondViewHiddenSearch"];
    
    self.activityArray = [[NSMutableArray alloc] init];
    self.hotPointArray = [[NSMutableArray alloc] init];
    self.bannerArray = [[NSMutableArray alloc] init];
    showOrNot = YES;
    
    hotPointBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    hotPointBtn.frame =CGRectMake(0,0,UI_SCREEN_WIDTH/2, UI_NAVIGATION_BAR_HEIGHT);
    hotPointBtn.backgroundColor = [UIColor clearColor];
    hotPointBtn.titleLabel.font = NAVIGATIONTITLEFONT;
    [hotPointBtn setTitle:@"数据凶猛" forState:UIControlStateNormal];
    [hotPointBtn setTitleColor:TEXTBLACKCOLORE3 forState:UIControlStateNormal];
    [hotPointBtn setTitleColor:TEXTBLACKCOLORE forState:UIControlStateDisabled];
    [hotPointBtn setTitleColor:TEXTBLACKCOLORE forState:UIControlStateHighlighted];
    [hotPointBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    [hotPointBtn setAdjustsImageWhenHighlighted:NO];
    hotPointBtn.enabled =NO;
    hotPointBtn.tag =btn_tag+1;
    [self.navigationBarView addSubview:hotPointBtn];

    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(width_x(hotPointBtn), 0, 1, UI_NAVIGATION_BAR_HEIGHT)];
    lineView.backgroundColor = RGBA(219, 219, 219, 1);
    [self.navigationBarView addSubview:lineView];
    
    //数据热点tabbar
    activityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    activityBtn.frame =CGRectMake(width_x(hotPointBtn)+1,0,UI_SCREEN_WIDTH/2, UI_NAVIGATION_BAR_HEIGHT-1);
    activityBtn.backgroundColor = [UIColor clearColor];
    activityBtn.titleLabel.font = NAVIGATIONTITLEFONT;
    [activityBtn setTitle:@"人人策画" forState:UIControlStateNormal];
    [activityBtn setTitleColor:TEXTBLACKCOLORE3 forState:UIControlStateNormal];
    [activityBtn setTitleColor:TEXTBLACKCOLORE forState:UIControlStateDisabled];
    [activityBtn setTitleColor:TEXTBLACKCOLORE forState:UIControlStateHighlighted];
    [activityBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    [activityBtn setAdjustsImageWhenHighlighted:NO];
    activityBtn.enabled =YES;
    activityBtn.tag =btn_tag;
    [self.navigationBarView addSubview:activityBtn];
    
    [self createActivityView];
    [self createHotPointView];
    
    [self hiddenActivity:YES andHiddenHotPointHearder:showOrNot andHiddenHotPointTableView:NO];
    
    [self getActivityData];
    [self getHotPointData];
    [self getBannerData];
    
    popUpView = [[XDPopUpView alloc] init];
    DDLOG(@"path = %@",NSHomeDirectory());

    
    [self.navigationBarView addSubview:rightBtn];
}

#pragma mark  ========================create UI==========================
-(void)createActivityView
{
    //“活动”图层
    self.activityTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, UI_SCREEN_WIDTH,self.contentView.frame.size.height-UI_TAB_BAR_HEIGHT) style:UITableViewStylePlain];
    _activityTableView.delegate = self;
    _activityTableView.dataSource = self;
    _activityTableView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_activityTableView];
}

-(void)createHotPointView
{
    //"数据热点"头部图片展示区域
    self.heardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_HEIGHT, hotHeaderViewHeight)];
//    _heardImageView.image = [UIImage imageNamed:@"44"];
    _heardImageView.backgroundColor = UIColorFromRGB(0xdbdada);
    [self.contentView addSubview:_heardImageView];
    
    //"数据热点"底层列表
    self.hotPointTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,height_y(_heardImageView), UI_SCREEN_WIDTH, self.contentView.frame.size.height-UI_TAB_BAR_HEIGHT-(height_y(_heardImageView))) style:UITableViewStylePlain];
    _hotPointTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _hotPointTableView.delegate = self;
    _hotPointTableView.dataSource =self;
    _hotPointTableView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_hotPointTableView];
}

#pragma mark  ========================UITableView Delegate==========================
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _activityTableView){;
        
        return [[_activityArray objectAtIndex:section] count];
    }
    else{
//        if ([[_hotPointArray  objectAtIndex:section] count]>10){
//            return 10;
//        }
        return [[_hotPointArray objectAtIndex:section] count];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == _activityTableView){
        DDLOG(@"_activityArray count = %d",[_activityArray count]);
        return [_activityArray count];
    }
    return [_hotPointArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(tableView == _activityTableView){
        return acitivtyHeaderHeight;
    }else{
        return hotPointHeaderHeight;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSString * string;
    NSArray * array;
    ActivityItem * item;
    CGFloat headerHeight=0;
    if (tableView == _activityTableView){
        headerHeight =acitivtyHeaderHeight;
        DDLOG(@"count = %d section = %d",[_activityArray count],section);
        NSArray * arr = [_activityArray objectAtIndex:section];
        item = [arr objectAtIndex:0];
        NSArray * arr2 = [item.activityStartTime componentsSeparatedByString:@"-"];
        string = [NSString stringWithFormat:@"%d年%d月",[[arr2 objectAtIndex:0]intValue],[[arr2 objectAtIndex:1]intValue]];
    }else{
        headerHeight = hotPointHeaderHeight;
        array = @[@"明星作品(10)",@"明星艺术家(10)",@"明星画廊(10)"];
    }
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, headerHeight)];
    view.backgroundColor = RGBA(217, 217, 217, 1);
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, UI_SCREEN_WIDTH-15, headerHeight)];
    label.textColor = TEXTBLACKCOLORE;
    label.font = [UIFont systemFontOfSize:13.5];
    label.backgroundColor = [UIColor clearColor];
    label.text = string;
    if (tableView == _hotPointTableView){
        label.text = [array objectAtIndex:section];
    }
    [view addSubview:label];
    return view;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _activityTableView){
        return 176/2.0f;
    }
    
    if (indexPath.section == 0){
        if (indexPath.row == 9){
            return 461/2.0f+20/2.0f+10/2.0f+10;
        }
        return 461/2.0f+20/2.0f+10/2.0f;
    }else{
        if (indexPath.row == 9){
            return 20/2.0f+82/2.0f+10;
        }
        return 20/2.0f+82/2.0f;
    }
}


-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView == _activityTableView){
        static NSString * cellName = @"cell";
        ActivityCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
        if (cell == nil){
            cell = [[ActivityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
            cell.backgroundColor = [UIColor clearColor];
        }
        
        if (_activityArray.count == 0){
            return cell;
        }
        
        ActivityItem * item = [[_activityArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        
        NSArray * arr = [item.activityStartTime componentsSeparatedByString:@"-"];
        
        cell.dayLabel.text =[arr objectAtIndex:2];
        cell.weekLabel.text = item.activityWeekTime;
        cell.titleLabel.text = item.activityTitle;
        BOOL isHaveSponsor;
        if (IS_NOT_EMPTY(item.activitySponsor)){
            if ([item.activitySponsor isEqualToString:@"<null>"]){
                isHaveSponsor = NO;
            }else{
                isHaveSponsor =YES;
                cell.sponsorLabel.text = [NSString stringWithFormat:@"主办:%@",item.activitySponsor];
                DDLOG(@"item.activitysponsor = %@",item.activitySponsor);
            }
        }
        if (IS_NOT_EMPTY(item.activityDesign)){
            if ([item.activityDesign isEqualToString:@"<null>"]){
            
            }else{
                cell.plannerLabel.text = [NSString stringWithFormat:@"策展人:%@",item.activityDesign];
                DDLOG(@"item.activityDesign = %@",item.activityDesign);
            }

        }
        
        if (isHaveSponsor){
            cell.plannerLabel.frame = CGRectMake(cell.titleLabel.frame.origin.x, height_y(cell.sponsorLabel)+10/2.0f, UI_SCREEN_WIDTH-162/2-(width_x(cell.weekLabel))+10, 12.5);
        }else{
            cell.plannerLabel.frame = cell.sponsorLabel.frame;
        }
        
        cell.browseLabel.text = item.beScanTime;
        CGRect rect = [XDTools xyAutoSizeOfWidget:cell.browseLabel andSize:CGSizeMake(100, 1000) andtextFont:11.5];
        cell.browseLabel.frame = CGRectMake(UI_SCREEN_WIDTH-rect.size.width-15, rect.origin.y, rect.size.width, rect.size.height);
        
        cell.rightImageView.frame = CGRectMake(cell.browseLabel.frame.origin.x-13/2.0f-24/2,74/2.0f, 24/2, 16/2);

        return cell;
    }else{
        if (indexPath.section == 0){
            static NSString * cellName = @"cell2";
            HotPointProductionCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
            if (cell == nil){
                cell = [[HotPointProductionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
                cell.backgroundColor = [UIColor clearColor];
            }
            
            NSDictionary * dic = [[_hotPointArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
            cell.numberImageView.image = [UIImage imageNamed:@"22"];
            cell.numberLabel.text = [NSString stringWithFormat:@"%d",indexPath.row+1];
            NSString * iamgeUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,[dic objectForKey:@"url_s"]];
            NSString * urlString=[iamgeUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [cell.productionImageView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"placehold_image"]];
            cell.nameLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"title"]];
            cell.authorLabel.text =[NSString stringWithFormat:@"%@",[dic objectForKey:@"author"]];
            cell.browseLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"beScanTime"]];
            cell.browseLabel.textAlignment = NSTextAlignmentRight;
            cell.collectLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"beStoreTime"]];
            cell.collectLabel.textAlignment = NSTextAlignmentRight;
            [cell.rightBtn addTarget:self action:@selector(showProductionData:) forControlEvents:UIControlEventTouchUpInside];
            cell.rightBtn.tag =cell_btn_tag+indexPath.row;
            return cell;
        }else{
            static NSString * cellName = @"cell3";
            HotPointNarrowCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
            if (cell == nil){
                cell = [[HotPointNarrowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
                cell.backgroundColor = [UIColor clearColor];
            }
            if (indexPath.row>9){
                return cell;
            }
            if (indexPath.section == 1){
                NSDictionary * dic = [[_hotPointArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
                cell.starNumberImageView.image = [UIImage imageNamed:@"22"];
                cell.numberLabel.text = [NSString stringWithFormat:@"%d",indexPath.row+1];
                
                NSString * iamgeUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,[dic objectForKey:@"url_s"]];
                NSString * urlString=[iamgeUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [cell.starHeardImageView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"11"]];
                cell.starNameLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"author"]];
                cell.artWorkCountLabel.text = [NSString stringWithFormat:@"%@件作品",[dic objectForKey:@"workCount"]];
                cell.starBrowseLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"beScanTime"]];;
                cell.starBrowseLabel.textAlignment = NSTextAlignmentRight;
                cell.starCollectLabel.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"beStoreTime"]];
                cell.starCollectLabel.textAlignment = NSTextAlignmentRight;
                [cell.rightBtn addTarget:self action:@selector(showProductionData:) forControlEvents:UIControlEventTouchUpInside];
                cell.rightBtn.tag = cell_btn_tag1+indexPath.row;
            }else{
                NSDictionary * dic = [[_hotPointArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
                cell.starNumberImageView.image = [UIImage imageNamed:@"22"];
                cell.numberLabel.text = [NSString stringWithFormat:@"%d",indexPath.row+1];
                
                NSString * iamgeUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,[dic objectForKey:@"url"]];
                NSString * urlString=[iamgeUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [cell.starHeardImageView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"11"]];
                
                cell.starNameLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"name"]];
                if ([[dic objectForKey:@"workCount"] intValue]>=0){
                    cell.artWorkCountLabel.text = [NSString stringWithFormat:@"%d件作品",[[dic objectForKey:@"workCount"] intValue]];
                }
                cell.starBrowseLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"beScanTime"]];
                cell.starCollectLabel.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"beStoreTime"]];
                [cell.rightBtn addTarget:self action:@selector(showProductionData:) forControlEvents:UIControlEventTouchUpInside];
                cell.rightBtn.tag = cell_btn_tag2+indexPath.row;
                     DDLOG(@"cell.productionImageView.imageurl = %@",urlString);
            }
            return cell;
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if(tableView == _activityTableView){
        DetailforActFirstVC *vc1 = [[DetailforActFirstVC alloc]init];
        DetailforActSecondVC *vc2 = [[DetailforActSecondVC alloc]init];
        DetailforActThirdVC *vc3 = [[DetailforActThirdVC alloc]init];
        ActivityItem * item = [[_activityArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        if ([item.type intValue]==1) {
            vc1.idStr = item.idStr;
            vc1.typeStr =item.type;
            [self.navigationController pushViewController:vc1 animated:YES];
        }
        if ([item.type intValue]==2) {
            vc2.idStr = item.idStr;
            vc2.typeStr = item.type;
            DDLOG(@"vc2.idstr = %@   %@",vc2.idStr,item.idStr);
            [self.navigationController pushViewController:vc2 animated:YES];
        }
        if ([item.type intValue]==3) {
            vc3.idStr = item.idStr;
            vc3.typeStr = item.type;
            [self.navigationController pushViewController:vc3 animated:YES];
        }
    }else{
        if (indexPath.section == 0){
            MostDetailViewController * vc = [[MostDetailViewController alloc] init];
            vc.workID = [[[_hotPointArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"id"];
            [self.navigationController pushViewController:vc animated:YES];
        }else if(indexPath.section){
            DetailforArtistVC * vc = [[DetailforArtistVC alloc] init];
            NSString * type;
            if (indexPath.section == 1){
                type = @"1";
            }else{
                type = @"2";
            }
            vc.typeStr =type;
            vc.idStr =[[[_hotPointArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"id"];
            DDLOG(@"type = %@,idstr = %@",vc.typeStr,vc.idStr);
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

#pragma mark  ========================UIButton 点击事件==========================
//切换活动和数据热点
-(void)btnClick:(UIButton * )sender
{
    activityBtn.enabled = sender.tag==btn_tag?NO:YES;
    hotPointBtn.enabled = sender.tag==btn_tag+1?NO:YES;
    
    if (sender.tag == btn_tag+1){
        [self hiddenActivity:YES andHiddenHotPointHearder:showOrNot andHiddenHotPointTableView:NO];
    }else{
        [self hiddenActivity:NO andHiddenHotPointHearder:YES andHiddenHotPointTableView:YES];
    }

}

//显示数据热点中某条的具体走势图
-(void)showProductionData:(UIButton *)sender
{
    
    
//    int a = sender.tag%10;
    int b = sender.tag/10;
    int index = sender.tag-cell_btn_tag;
    int index1 = sender.tag -cell_btn_tag1;
    int index2 = sender.tag- cell_btn_tag2;
    if (b==0){
//        //来自"明星作品" index.row = a-cell_btn_tag
        NSString *_Work_idSTR = [[[_hotPointArray objectAtIndex:0] objectAtIndex:index] objectForKey:@"id"];
        _Work_idSTR = [NSString stringWithFormat:@"%@",_Work_idSTR];
        
        [popUpView GetStarWorkPVInfoById:_Work_idSTR];
        
    }else if (b==1){
        //来自“明星艺术家”
        
        NSString *_Work_idSTR = [[[_hotPointArray objectAtIndex:1] objectAtIndex:index1] objectForKey:@"id"];
        _Work_idSTR = [NSString stringWithFormat:@"%@",_Work_idSTR];
        
        [popUpView GetStarArtistPVInfoById:_Work_idSTR];
        
        
    }else{
        //来自”明星画廊“
        NSString *_Work_idSTR = [[[_hotPointArray objectAtIndex:2] objectAtIndex:index2] objectForKey:@"id"];
        _Work_idSTR = [NSString stringWithFormat:@"%@",_Work_idSTR];
        
        [popUpView GetStarGalleryPVInfoById:_Work_idSTR];
        
    }
   [popUpView setpopupviewshow:YES];
}

#pragma mark  ======================控制活动和数据热点显示隐藏切换====================
-(void)hiddenActivity:(BOOL)isAct andHiddenHotPointHearder:(BOOL)isHot andHiddenHotPointTableView:(BOOL)isHotT
{

    _activityTableView.hidden = isAct;
    _heardImageView.hidden =isHot;
    _hotPointTableView.hidden = isHotT;
}

#pragma mark ======================数据请求==========================================
-(void)getActivityData
{
    //获取活动列表页数据
    if ([XDTools NetworkReachable]){
    NSString *body = [NSString stringWithFormat:@" <ActivityList xmlns=\"http://tempuri.org/\">"
                      "</ActivityList>"];
    
    __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:ACTIVITYLIST];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
//            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    //请求成功
                    
                    [_activityArray removeAllObjects];
                    NSMutableArray * tmpArray = [NSMutableArray arrayWithArray:[responseDict objectForKey:@"activityList"]];
                    NSMutableArray * tmpArray2 = [[NSMutableArray alloc] init];
                    NSMutableArray * tmpArray3 = [[NSMutableArray alloc] init];
                    
                    for (NSDictionary * dic in tmpArray){
                       
                        ActivityItem * item = [[ActivityItem alloc] init];
                        item.activityDesign = [NSString stringWithFormat:@"%@",[dic objectForKey:@"activityDesign"]];
                        item.activitySponsor = [NSString stringWithFormat:@"%@",[dic objectForKey:@"activitySponsor"]];
                        item.activityStartTime = [NSString stringWithFormat:@"%@",[dic objectForKey:@"activityStartTime"]];
                        item.activityTitle = [NSString stringWithFormat:@"%@",[dic objectForKey:@"activityTitle"]];
                        item.beScanTime = [NSString stringWithFormat:@"%@",[dic objectForKey:@"beScanTime"] ];
                        item.coorganizer = [NSString stringWithFormat:@"%@",[dic objectForKey:@"coorganizer"] ];
                        item.organizer = [NSString stringWithFormat:@"%@",[dic objectForKey:@"organizer"] ];
                        item.idStr = [NSString stringWithFormat:@"%@",[dic objectForKey:@"id"]];
                        item.activityWeekTime = [NSString stringWithFormat:@"%@",[dic objectForKey:@"activityWeekTime"]];
                        item.type = [NSString stringWithFormat:@"%@",[dic objectForKey:@"type"]];
                        [tmpArray2 addObject:item];
                        [tmpArray3 addObject:item];
                    }
                    
                    for (int k =2015;k >=2013;k--)
                    {
                        NSMutableArray * mArray = [[NSMutableArray alloc] init];
                        for (int j =12;j>=1;j--)
                        {
                            for (int i =0;i<[tmpArray2 count];i++)
                            {
                                ActivityItem * item = [[ActivityItem alloc] init];
                                item = [tmpArray2 objectAtIndex:i];
                                NSArray * arr = [item.activityStartTime componentsSeparatedByString:@"-"];
                                int year = [[arr objectAtIndex:0] intValue];
                                int month = [[arr objectAtIndex:1] intValue];
                                if (year ==k&&month==j){
                                    [mArray addObject:item];
                                }
                            }
                            if ([mArray count]){

                                NSArray *xyArr = [[NSArray alloc] initWithArray:mArray];
                                [_activityArray addObject:xyArr];
                                ActivityItem * item2 = [mArray objectAtIndex:0];
                                DDLOG(@"item2.acivityTitle= %@",item2.activityTitle);
                                [mArray removeAllObjects];
                            }
                        }
                    }
                
                    DDLOG(@"%d",_activityArray.count);
                    DDLOG(@"%d  %d  %d",[[_activityArray objectAtIndex:0] count],
                                        [[_activityArray objectAtIndex:1] count],
                          [[_activityArray objectAtIndex:2] count]);
                    
//                    if ([tmpArray2 count]>0){
//                        int Year=0;
//                        int month=0;
//           
//                        BOOL flag = NO;
//                        NSMutableArray * array1 = [[NSMutableArray alloc] init];
//                        NSMutableArray * array2 = [[NSMutableArray alloc] init];
//                        NSMutableArray * array3 = [[NSMutableArray alloc] init];
//                        for (int i =0;i<[tmpArray2 count];i++){
//                            ActivityItem * item = [tmpArray2 objectAtIndex:i];
//                            NSArray * arr = [item.activityStartTime componentsSeparatedByString:@"-"];
//                            if([[arr objectAtIndex:1] intValue]==1){
//                                [array1 addObject:item];
//                            }else if ([[arr objectAtIndex:1] intValue]==3){
//                                [array2 addObject:item];
//                            }else{
//                                [array3 addObject:item];
//                            }
//                        }
//                        
//                        [_activityArray addObject:array1];
//                        [_activityArray addObject:array2];
//                        [_activityArray addObject:array3];
//                    }
//                    
//                    ActivityItem * atime =   [[_activityArray objectAtIndex:0] objectAtIndex:0];
//                    DDLOG(@"aaaatime = %@",atime.activityStartTime);
//                    ActivityItem * btime =   [[_activityArray objectAtIndex:1] objectAtIndex:0];
//                    DDLOG(@"bbbbtime = %@",btime.activityStartTime);
//                    ActivityItem * ctime =   [[_activityArray objectAtIndex:2] objectAtIndex:0];
//                    DDLOG(@"cccctime = %@",ctime.activityStartTime);
                    
                }
                [_activityTableView reloadData];
            }
        }];

        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}

-(void)getBannerData
{
    //获取数据热点轮播图片数据
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <DataHotList xmlns=\"http://tempuri.org/\">"
                          "</DataHotList>"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:DATAHOTLIST];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            //            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                
                DDLOG(@"aaaaa = %@",responseDict);
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    [_bannerArray removeAllObjects];
                    showOrNot = ![[responseDict objectForKey:@"showOrNot"] boolValue];
                  
                    if(!showOrNot){
                        _heardImageView.hidden =NO;
                        _heardImageView.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH, hotHeaderViewHeight);
//                        [_heardImageView setImageWithURL:<#(NSURL *)#>]
                        _hotPointTableView.frame = CGRectMake(0,height_y(_heardImageView), UI_SCREEN_WIDTH, self.contentView.frame.size.height-UI_TAB_BAR_HEIGHT-(height_y(_heardImageView)));
                        NSArray *arr = [responseDict objectForKey:@"urlLists"];
                        [_bannerArray addObjectsFromArray:arr];
                        [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(changePicBanner) userInfo:nil repeats:YES];
//                        for (NSDictionary * dicc in [responseDict objectForKey:@"urlLists"]){
//                            NSString * str = [dicc objectForKey:@""]
//                        }
                        
                    }else{
                        _heardImageView.hidden =YES;
                        _hotPointTableView.frame = CGRectMake(0,0, UI_SCREEN_WIDTH, self.contentView.frame.size.height-UI_TAB_BAR_HEIGHT);
                    }
                }
            }
        }];
        
        [request setFailedBlock:^{
        }];
        
        [request startAsynchronous];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }

}

-(void)getHotPointData
{
    //获取数据热点列表页数据
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <StarList xmlns=\"http://tempuri.org/\">"
                          "</StarList>"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:STARWORKLIST];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            //            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    //请求成功
                    NSString * artistsListString = [responseDict objectForKey:@"StarArtistsList"];
                    NSString * artorkListString = [responseDict objectForKey:@"StarArtorkList"];
                    NSString * gallerListString = [responseDict objectForKey:@"StarGalleryList"];
                    
                    NSDictionary * starArtistsListDict = [XDTools JSonFromString:artistsListString];
                    NSDictionary * starArtorkListDict = [XDTools JSonFromString:artorkListString];
                    NSDictionary * starGalleryListDict = [XDTools JSonFromString:gallerListString];
                    
                    //如果要判断code的话就在这里判断
                    NSMutableArray * starArtsArray = [NSMutableArray arrayWithArray:[starArtistsListDict objectForKey:@"starArtsList"]];
                    NSMutableArray * starWorkArray = [NSMutableArray arrayWithArray:[starArtorkListDict objectForKey:@"starWorkList"]];
                    NSMutableArray * starGalleryArray = [NSMutableArray arrayWithArray:[starGalleryListDict objectForKey:@"starGalleryList"]];
                    
                    [_hotPointArray removeAllObjects];
                
                    [_hotPointArray addObject:starWorkArray];
                    [_hotPointArray addObject:starArtsArray];
                    [_hotPointArray addObject:starGalleryArray];
                }
            }
            [_hotPointTableView reloadData];
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}
-(void)changePicBanner{
    if (bannerIndex>=_bannerArray.count) {
        bannerIndex = 0;
    }
    NSString *urlString = [_bannerArray objectAtIndex:bannerIndex];
    [_heardImageView setImageWithURL:[NSURL URLWithString:urlString]];
    bannerIndex++;
}

//图像识别测试
-(void)knowPic{
    DSAppController *slidingMenuController = [[DSAppController alloc] initWithRootViewController:nil];
    
    [slidingMenuController setARDelegate:self];
    
    [self presentViewController:slidingMenuController animated:YES completion:nil];
}
//实现代理方法
-(void)getARResult:(NSString *)dataID{
    MostDetailViewController *mosVC = [[MostDetailViewController alloc] init];
    mosVC.workID = dataID;
    [self.navigationController pushViewController:mosVC animated:YES];
    DDLOG(@"dataId = %@",dataID);
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
